package com.huaixia.cozeapi.response;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 * @author crg
 * @date 2024/06/25 14:36
 */
@SuppressWarnings("unused")
@Data
public class ApiResponse<T> implements Serializable {
	public static final int SUCCESS_CODE = 200;
	@ApiModelProperty(value = "状态码")
	private int code = 200;
	@ApiModelProperty(value = "消息")
	private String msg = "成功";
	@ApiModelProperty("数据")
	private T data;

	public ApiResponse() {

	}

	public ApiResponse(T data) {
		this.data = data;
	}

	public void setCodeAndMsg(ResponseCodeInterface response) {
		this.code = response.getCode();
		this.msg = response.getMsg();
	}

	public ApiResponse(String msg) {
		this.msg = msg;
	}

	public ApiResponse(int code, String msg) {
		this.code = code;
		this.msg = msg;
	}

	public ApiResponse(int code, T data) {
		this.code = code;
		this.data = data;
	}

	public ApiResponse(ResponseCode httpState, String msg) {
		this.code = httpState.getCode();
		this.msg = msg;
	}

	public ApiResponse(ResponseCode httpState, T data) {
		this.code = httpState.getCode();
		this.msg = httpState.getMsg();
		this.data = data;
	}

	public ApiResponse(int code, String msg,T date){
		this.code = code;
		this.msg = msg;
		this.data = date;
	}

	public ApiResponse(int code, boolean state, T data) {
		this.code = code;
		this.data = data;
	}

	public ApiResponse(int code, boolean state, String msg) {
		this.code = code;
		this.msg = msg;
	}

	public ApiResponse(ResponseCode httpState, boolean state, String msg) {
		this.code = httpState.getCode();
		this.msg = msg;
	}

	public ApiResponse(ResponseCode httpState, boolean state, T data) {
		this.code = httpState.getCode();
		this.msg = httpState.getMsg();
		this.data = data;
	}

	public static<T> ApiResponse<T> ok(){
		return new ApiResponse<>();
	}

	public static<T> ApiResponse<T> ok(T data){
		return new ApiResponse<>(data);
	}

	public static<T> ApiResponse<T> ok(int code, T data){
		return new ApiResponse<>(code,data);
	}

	public static<T> ApiResponse<T> ok(ResponseCode httpState){
		return new ApiResponse<>(httpState.getCode(),httpState.getMsg(),null);
	}

	public static<T> ApiResponse<T> ok(ResponseCode httpState, T data){
		return new ApiResponse<>(httpState.getCode(),httpState.getMsg(),data);
	}

	public static<T> ApiResponse<T> error(String msg){
		return new ApiResponse<>(ResponseCode.ERROR,msg);
	}

	public static<T> ApiResponse<T> error(T data){
		return new ApiResponse<>(ResponseCode.ERROR,data);
	}

	public static<T> ApiResponse<T> error(int code, String msg){
		return new ApiResponse<>(code,msg);
	}

	public static<T> ApiResponse<T> error(int code, T data){
		return new ApiResponse<>(code,data);
	}

	public static<T> ApiResponse<T> error(ResponseCode httpState){
		return new ApiResponse<>(httpState.getCode(),httpState.getMsg());
	}

	public static<T> ApiResponse<T> error(ResponseCode httpState, T data){
		return new ApiResponse<>(httpState.getCode(),httpState.getMsg(),data);
	}
}